<template>
   <div class="app-container">
       <!-- 头部 -->
        <mt-header fixed title="固定在顶部" class="head">
            <router-link to="/" slot="left">
                <mt-button icon="back" @click="goBack" v-if="flag">返回</mt-button>
            </router-link>
        </mt-header>
        <!-- <h1>根组件</h1> -->

        <!-- 组件坑 -->
        <transition>
		       <router-view></router-view>
		</transition>



        <!-- 底部 -->
        <nav class="mui-bar mui-bar-tab">
			<router-link class="mui-tab-item-my" to="/index">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</router-link>
			<router-link class="mui-tab-item-my" href="#tabbar-with-chat" to="/member">
				<span class="mui-icon mui-icon-contact"></span>
				<span class="mui-tab-label">会员</span>
			</router-link>
			<router-link class="mui-tab-item-my" href="#tabbar-with-contact" to="/cart">
				<span class="mui-icon mui-icon-extra mui-icon-extra-cart"><span class="mui-badge" id="badge">0</span></span>
				<span class="mui-tab-label">购物车</span>
			</router-link>
			<router-link class="mui-tab-item-my" href="#tabbar-with-map" to="/search">
				<span class="mui-icon mui-icon-search"></span>
				<span class="mui-tab-label">搜索</span>
			</router-link>
		</nav>
   </div>
</template>


<script>
import { Indicator } from "mint-ui";
export default {
  data(){
	  return {
		flag:false
	  }
  },
  methods: {
	  //返回功能
	  goBack(){
		//   console.log(this)
		this.$router.go(-1)
	  },
	  //loading效果
    interceptors() {
      axios.interceptors.request.use(function(config) {
        // Do something before request is sent
        Indicator.open({
          text: "加载中...",
          spinnerType: "fading-circle"
        });
        return config;
      });

      // Add a response interceptor
      axios.interceptors.response.use(function(response) {
		// Do something with response data
		Indicator.close();
        return response;
      });
    }
  },
  //用watch监视hash值，当是首页的时候不显示返回按钮
  watch:{
	  '$route.path':{
		  handler:function(newVal){
		//   console.log(newVal)
		//   if(newVal==='/index'){
		// 	  this.flag=false;
		//   }else{
		// 	  this.flag=true;
		//   }
			this.flag=!(newVal==='/index')
		},
		immediate:true
	  }
  }
};
</script>


<style lang="scss" scoped>
.head{
  z-index:10;
}
.v-enter,
.v-leave-to {
  opacity: 0;
  transform: translateX(100%);
}

.v-enter-active,
.v-leavt-active {
  // opacity:1;
  transition: all 0.4s ease;
}

h1 {
  color: green;
}
.app-container {
  padding-top: 40px;
  background-color: #fff;
  overflow: hidden;
  padding-bottom: 50px;
}

.mui-bar-tab .mui-tab-item-my {
    display: table-cell;
    overflow: hidden;
    width: 1%;
    height: 50px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #929292;
}
.mui-bar-tab .mui-tab-item-my .mui-icon {
    top: 3px;
    width: 24px;
    height: 24px;
    padding-top: 0;
    padding-bottom: 0;
}
.mui-bar-tab .mui-tab-item-my .mui-icon ~ .mui-tab-label {
    font-size: 11px;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mui-bar-tab .mui-tab-item-my.mui-active[data-v-38cab9c1] {
    color: #007aff;
}
</style>
